const listItemBehavior = Behavior({
  data: {
    index: -1,
    isLast: false,
    bordered: false,
  },

  methods: {
    updateElementSN(index, isLast, bordered) {
      this.setData({ index, isLast, bordered })
    },
  },
})

const listParentBehavior = Behavior({
  methods: {
    assignElementSN(listItem) {
      if (!listItem) throw new Error('The item name is missing.')

      const elements = this.getRelationNodes(listItem)
      if (elements && elements.length > 0) {
        const lastIndex = elements.length - 1
        elements.forEach((element, index) => {
          element.updateElementSN(index, index === lastIndex, this.data.bordered)
        })
      }
    },
  },
})

module.exports = {
  listItemBehavior,
  listParentBehavior,
}
